<template>
  <div class="todo-footer" v-show="total">
    <label>
      <input type="checkbox" v-model="is_all" />
    </label>
    <span>
      <span>已完成{{ done_total }}</span> / 全部{{ total }}
    </span>
    <button class="btn btn-danger" @click='$emit("clear_all")'>清除已完成任务</button>
  </div>
</template>

<script>
export default {
  name: "Footer",
  computed: {
    total() {
      return this.todos.length
    },
    done_total() {
      return this.todos.reduce((pre, current) => current.done ? pre + 1 : pre, 0)
    },
    is_all: {
      get() {
        return this.total === this.done_total && this.total > 0
      },
      set(value) {
        this.$emit("check_all_todos", value)
      }
    },

  },
  props: {
    todos: {
      type: Array,
      required: true,
    }
  }
}
</script>

<style lang="less" scoped>
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>